#import "NSURL+CTURL.h"
#import "NSString+Tools.h"
#import <objc/runtime.h>
@implementation NSURL (CTURL)
+ (NSURL *)fullUrlForImg:(NSString *)urlString {
    if(beNil(urlString)) {
        return [NSURL URLWithString:@""];
    }
    if([urlString containsString:@"http"]) {
        return [NSURL URLWithString:urlString];
    } else {
        NSString *baseUrl = [CTEnvironmentManager shareManager].environmentUrl;
        NSString *pathUrl = [CTEnvironmentManager shareManager].imagePath;
        NSString *fullUrl = [NSString stringWithFormat:@"%@%@%@",baseUrl, pathUrl, urlString];
        return [NSURL URLWithString:fullUrl];
    }
}
+ (NSString *)fullUrlStringForWeb:(NSString *)urlPath {
    if(beNil(urlPath)) {
        return @"";
    }
    NSString *baseUrl = [CTEnvironmentManager shareManager].environmentH5Url;
    NSString *fullUrl = [NSString stringWithFormat:@"%@%@", baseUrl, urlPath];
    return fullUrl;
}
+ (NSString *)fullUrlStringForUpreport:(NSString *)urlPath {
    if(beNil(urlPath)) {
        return @"";
    }
    NSString *baseUrl = [CTEnvironmentManager shareManager].environmentH5Url;
    NSString *pathUrl = [CTEnvironmentManager shareManager].reportPath;
    NSString *fullUrl = [NSString stringWithFormat:@"%@%@%@", baseUrl, pathUrl,urlPath];
    return fullUrl;
}
+ (void)hookUrl
{
    Method ori_Method =  class_getClassMethod([NSURL class], @selector(URLWithString:));
    Method my_Method = class_getClassMethod([NSURL class], @selector(hook_URLWithString:));
    method_exchangeImplementations(ori_Method, my_Method);
}
+(instancetype)hook_URLWithString:(NSString *)URLString
{
    if ([NSString isEmpty:URLString]) {
        NSLog(@"NSURL+NSNull : nsurl init catch nsnull");
        return nil;
    }
    return [self hook_URLWithString:URLString];
}
@end
